package sartoservicesync.utils;

import java.net.Authenticator;
import java.net.InetAddress;
import java.net.PasswordAuthentication;

/**
 * Created by waldemar.lammert on 17.06.2014.
 */
public class PrestaAuthenticator extends Authenticator {
    private String webserviceKey;

    public PrestaAuthenticator(String webserviceKey){
        this.webserviceKey= webserviceKey;
    }
    // This method is called when a password-protected URL is accessed
    protected PasswordAuthentication getPasswordAuthentication() {
        // Get information about the request
        String promptString = getRequestingPrompt();
        String hostname = getRequestingHost();
        InetAddress ipaddr = getRequestingSite();
        int port = getRequestingPort();
        String password = "";
        // Username = Webservicekey, no password needed!
        String username = webserviceKey;
        return new PasswordAuthentication(username, password.toCharArray());
    }
}
